-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Reviews to Subjects #597
base: add-shoulda-matchers-gem
Are you sure you want to change the base?
Conversation
7436f62
to
fdd05ad
Compare
dfc5c9b
to
d4cb4f7
Compare
d4cb4f7
to
c3adc20
Compare
create_table :reviews do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.references :subject, null: false, foreign_key: true | ||
t.integer :rating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make this not null
?
def create | ||
@review = current_user.reviews.create!(subject_id: params[:subject_id], rating: params[:rating]) | ||
|
||
redirect_to subject_path(@review.subject) | ||
end | ||
|
||
def update | ||
@review.update!(rating: params[:rating]) | ||
|
||
redirect_to subject_path(@review.subject) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about combining these two actions and doing an "update or create"?
<%= link_to new_user_session_path do %> | ||
<div class="login-container"> | ||
Inicia sesión para calificar | ||
<span class="material-symbols-outlined"> | ||
login | ||
</span> | ||
</div> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we show the same stars, but when an unauthenticated user clicks them we redirect them to log in?
@@ -0,0 +1,5 @@ | |||
class AddAverageRatingToSubjects < ActiveRecord::Migration[7.1] | |||
def change | |||
add_column :subjects, :average_rating, :float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm ok with adding this, but i wonder if we should start with calculating it on the fly
</div> | ||
<% if current_user %> | ||
<div class="rating-item"> | ||
<% for value in 1..5 %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<% for value in 1..5 %> | |
<% 1.upto(5).each |value| %> |
<div class="rating-container"> | ||
<div class="rating-item"> | ||
<button class="material-icons mdc-icon-button">star</button> | ||
<%= @subject.average_rating.present? ? @subject.average_rating : "Sin calificar" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<%= @subject.average_rating.present? ? @subject.average_rating : "Sin calificar" %> | |
<%= @subject.average_rating || "Sin calificar" %> |
transition: transform 0.25s ease; | ||
|
||
&:hover { | ||
transform: scale(1.3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it easy/worth it highlighting all the stars to the left of the one that is on hover?
Purpose
Add the ability to submit 1-5 stars reviews to a
Subject
.Summary
Review
model that for eachUser
andSubject
will store arating
average_rating
column toSubject
to store the average of all the reviews associated with itSubject
'saverage_rating
every time aReview
associated with it changesReviewsController
Subjects
view to show and submit reviews for a particular subjectGuidance 👀
Before adding any system specs to test the new UI. I would like to know your thoughts on the current approach, what's missing and what's not necessary
##Demo
Screen.Recording.2024-11-20.at.6.57.59.PM.mov